package com.lz.water.monitor.util;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.ImmutableMap;

/**
 * http数据包装类
 * 
 * @author hhl
 *
 */
public final class ResponseDataPackageUtils {

	// private static final Multimap<Object, Object> EMPTY_MAP = new
	// ImmutableMultimap.Builder<Object, Object>()
	// .build();ImmutableMap.builder()
	// .build();

	private static final Map<Object, Object> EMPTY_MAP = ImmutableMap.builder()
			.build();

	private ResponseDataPackageUtils() throws Exception {
		throw new Exception();
	}

	/**
	 * 失败
	 * 
	 * @param status
	 * @param msg
	 * @return
	 */
	public static String fail(int status, String msg) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(BusinessConsts.STATUS, status);
		map.put(BusinessConsts.MSG, msg);
		map.put(BusinessConsts.DATA, EMPTY_MAP);
		return JSON.toJSONString(map);
	}

	/**
	 * 成功,不返回任何数据
	 * 
	 * @return
	 */
	public static String success() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(BusinessConsts.STATUS, CommonMsgEnum.SUCESS.getStatus());
		map.put(BusinessConsts.MSG, CommonMsgEnum.SUCESS.getMsg());
		map.put(BusinessConsts.DATA, EMPTY_MAP);
		return JSON.toJSONString(map);
	}

	/**
	 * 成功,返回数据
	 * 
	 * @param object
	 * @return
	 */
	public static String success(Object object) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(BusinessConsts.STATUS, CommonMsgEnum.SUCESS.getStatus());
		map.put(BusinessConsts.MSG, CommonMsgEnum.SUCESS.getMsg());
		map.put(BusinessConsts.DATA, object);
		return JSON.toJSONString(map);
	}

}
